import 'dart:convert';

import 'package:creatures_world/net/simple_response.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';

import 'net_requester.dart';

// import 'package:dio/src/response.dart' as DResponse;

class TaxonService {
  // static bool encode = true; //数据是否加密

  static bool debug = kDebugMode;
  static NetRequester netRequester = NetRequester();
  static String lang = "en-US";
  static String baseInaturaUrl = "https://api.inaturalist.org";

  static bool isDebug() {
    return debug;
  }

  static bool isEncode() {
    return !isDebug();
  }

  static Future<Response> speciesCounts(Map<String, dynamic> data, {bool showDialog = false}) async {
    //https://api.inaturalist.org/v1/observations/species_counts?locale=zh-cn&page=1&per_page=30&quality_grade=needs_id,research&order_by=created_at&order=desc
    String path = "${baseInaturaUrl}/v1/observations/species_counts?";
    var ret = netRequester.get(path, data, {});
    return ret;
  }

  static Future<SimpleResponse> getSpeciesDetail(String id, {bool showDialog = false}) async {
    String path = "${baseInaturaUrl}/v1/taxa/${id}?locale=${lang}";
    var ret = await netRequester.get(path, {}, {});
    if (200 == ret.statusCode) {
      var data = jsonDecode(ret.data);
      return SimpleResponse.simple_list(ret.statusMessage, ret.statusCode!, data_list: data["results"]);
    } else {
      return SimpleResponse.simple(ret.statusMessage, ret.statusCode!);
    }
  }

  ///删除Push消息
  static Future<Response> xx(String id, {bool showDialog = false}) async {
    String path = "/appuser/v1/api/user-remind/delete";
    var response = await netRequester.post(path, "jsonstring", ResponseType.json, showDialog: showDialog);
    return response;
  }
}
